import { ApiCall } from "tsrpc";
import { ReqGetData, ResGetData } from "../shared/protocols/PtlGetData";
import { Global } from "../models/Global";

// This is a demo code file
// Feel free to delete it

export default async function (call: ApiCall<ReqGetData, ResGetData>) {
    let op = await Global.db.collection("Asset").find().toArray();

    if (!op) {
        call.error('Post 不存在');
        return;
    }


    call.succ({
        data: op.map(item => ({
            RukuDate: item.RukuDate,
            AssetNum: item.AssetNum,
            SerialNum: item.SerialNum,
            EquipmentName: item.EquipmentName,
            EquipmentModel: item.EquipmentModel,
            Flag: item.Flag,
            Custodian: item.Custodian,
            DepartmentHead: item.DepartmentHead,
            _id: item._id.toString()
        }))
    })
}
